<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>火车票-粤亮旅游网</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/train.css">
    <!-- 引入字体图标 -->
    <style>
        @font-face {
            font-family: 'icomoon';
            src: url('fonts/icomoon.eot?rghiog');
            src: url('fonts/icomoon.eot?rghiog#iefix') format('embedded-opentype'),
            url('fonts/icomoon.ttf?rghiog') format('truetype'),
            url('fonts/icomoon.woff?rghiog') format('woff'),
            url('fonts/icomoon.svg?rghiog#icomoon') format('svg');
            font-weight: normal;
            font-style: normal;
            font-display: block;
        }
    </style>
    <script src="../js/jquery-3.3.1.js"></script>
</head>

<body>
<!-- 快捷导航栏开始 -->
<section class="shortcut">
    <div class="top-bgc">
        欢迎来到粤亮旅游网!
    </div>
    <div class="w">
        <div class="mine">
            <ul>
                <li class="fl">
                    <a href="collect.html">我的收藏</a>
                    &nbsp;&nbsp;&nbsp;
                    <a href="orders.html">我的订单</a>
                    &nbsp;&nbsp;&nbsp;
                    <a href="#" class="logout">退出</a>
                </li>
            </ul>
        </div>

    </div>
</section>
<!-- 导航栏 -->
<div class="nav w">
    <ul>
        <li><a href="index.html">首页</a></li>
        <li><a href="#">分类</a></li>
        <li><a href="#">旅游套餐</a></li>
        <li><a href="#" style="color: skyblue; font-size: 30px;">火车票</a></li>
        <li><a href="hotel.html">酒店</a></li>
        <li><a href="#">租车</a></li>
        <li><a href="#">活动</a></li>
        <li><a href="#">购物车</a></li>
        <li><a href="#">优惠券</a></li>
    </ul>
</div>
<!-- 核心内容部分 -->
<div class="box w">
    <div class="content">
        <div class="tit">火车票购买</div>
        <div class="address">
            <div class="start addr">
                <span>出发城市</span>
                <input type="text" class="start-address">
            </div>
            <div class="change"></div>
            <div class="end addr">
                <span>到达城市</span>
                <input type="text" class="end-address">
            </div>
        </div>
        <div class="departure-date">
            <span>出发日期</span>
            <input type="date" id="date" class="date">
            <div id="week"></div>
        </div>

        <button class="ticket-search">
            搜索
        </button>
    </div>
</div>
<script src="../js/train.js"></script>
<script>
    const search = document.querySelector('.ticket-search')

    search.addEventListener('click', function () {
        const departureStation = $(".box .content .address .start .start-address").val();
        const arrivalStation = $(".box .content .address .end .end-address").val();
        const departureDate = $(".box .content .departure-date .date").val();
        const week = document.getElementById('week').innerHTML;
        if (departureStation && arrivalStation && departureDate) {
            const requestData = {
                departureStation: departureStation,
                arrivalStation: arrivalStation,
                week: week,
                departureTime: departureDate,
            }

            localStorage.setItem('queryTickets', JSON.stringify(requestData));

            window.location.href = 'train-search.html'
        } else {
            alert("请输入出发站或者到达站")
        }
    })

    const logout = document.querySelector('.logout')
    logout.addEventListener('click',function (){
        $.ajax({
            url: "/logout",
            type: "POST",
            contentType: "application/json",
            success: function (response) {
                // 处理响应
                if (response.success === 1) {
                    alert("退出成功");
                    localStorage.removeItem('responseData');
                    localStorage.removeItem('hotelDetail')
                    localStorage.removeItem('cityData')
                    localStorage.removeItem('queryTickets')
                    // 进行跳转或其他操作
                    window.location.href = 'index.html'
                } else {
                    alert("退出失败");
                }
            },
            error: function () {
                alert("请求失败");
            }
        });
    })
</script>
</body>

</html>